package ch01;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author Jane
 * @date 2024-03-15 16:19
 */

public class TestStuMethods {
    public static void main(String[] args) throws InstantiationException
            , IllegalAccessException
            , NoSuchMethodException
            , InvocationTargetException, ClassNotFoundException {
        Class c1 = Student.class;

        Object zwt = c1.newInstance();
        //调用setStuName的方法 给对象赋值

        //获取指定的方法名称
        Method setStuName = c1.getDeclaredMethod("setStuName", String.class);
        c1.getDeclaredMethod("setStuNo", int.class).invoke(zwt,5);
        c1.getDeclaredMethod("setAge", int.class).invoke(zwt,20);

        //执行set方法
        setStuName.invoke(zwt,"小张呀");

        //执行get方法
      /*  Method getStuName = c1.getDeclaredMethod("getStuName");
        String res = getStuName.invoke(zwt).toString();
        System.out.println(res);*/
       /* Object stuName = c1.getDeclaredMethod("getStuName").invoke(zwt);
        System.out.println(stuName);*/

        Object show = c1.getDeclaredMethod("show").invoke(zwt);
        System.out.println(show);


    }
}
